import Vue from 'vue'
import co from 'co'
import * as Util from '../components/Util'

let modifyBillNumberGen = function * (data) {
  console.log('222222222222',data)
  let billdata = {
    billcoll: {
      id: data.f_billcoll_id,
      f_bill_id: data.f_bill_id + 1
    },
    detail: {
      f_billcoll_id: data.f_billcoll_id,
      f_bill_id: data.f_bill_id,
      f_userinfo_id: data.f_userinfo_id,
      f_user_id: data.f_user_id,
      f_user_name: data.f_user_name,
      f_hand_id: data.f_hand_id,
      f_charge_id: data.f_charge_id,
      f_total_money: data.f_total_money,
      f_paid_money: data.f_paid_money,
      f_operator: Util.f.name,
      f_filiale: Util.f.f_fengongsi,
      f_outlets: Util.f.f_parentname,
      f_bill_style: data.f_bill_style[0],
      f_bill_state: '有效',
      f_operator: Util.f.name,
      f_filiale: Util.f.f_fengongsi,
      f_outlets: Util.f.f_parentname,
      f_cause: data.f_cause
    }
}
  return Vue.resetpost('rs/logic/printBill', {data: billdata}, {resolveMsg: '打印发票成功', rejectMsg: '打印发票失败'})
}
let reissueBillGen = function * (data) {
  let selldetail = yield co(Vue.resetpost('rs/sql/singleTable_OrderBy', {data: {orderitem: 'id', items: '*',
   tablename: 't_sellingwater', condition: 'id = ' + data.id +  ' and f_charge_state = ' + "'" + '有效' + "'"}}, {resolveMsg: null, rejectMsg: null}))
  data.billdetail = selldetail.data[0]
  let billdata = {
    billcoll: {
      id: data.f_billcoll_id,
      f_bill_id: data.f_bill_id + 1
    },
    detail: {
      f_billcoll_id: data.f_billcoll_id,
      f_bill_id: data.f_bill_id,
      f_userinfo_id: data.billdetail.f_userinfo_id,
      f_user_id: data.billdetail.f_user_id,
      f_user_name: data.billdetail.f_user_name,
      f_hand_id: data.billdetail.f_hand_id,
      f_charge_id: data.billdetail.f_charge_id,
      f_total_money: data.billdetail.f_preamount,
      f_paid_money: data.billdetail.f_collection,
      f_bill_type: data.f_bill_type,
      f_bill_style: data.f_bill_style[0],
      f_bill_state: '有效',
      f_operator: Util.f.name,
      f_filiale: Util.f.f_fengongsi,
      f_outlets: Util.f.f_parentname,
      f_cause: data.f_cause
    }
    }
  return Vue.resetpost('rs/logic/printBill', {data: billdata}, {resolveMsg: '打印发票成功', rejectMsg: '打印发票失败'})
}
let PrintService = {
  install (Vue, options) {
    // 给vue增添对话框显示方法
    Vue.PrintService = Vue.prototype.$PrintService = PrintService
  },
  // 打印发票
  modifyBillNumber (data) {
    return co(modifyBillNumberGen(data))
  },
  ReissueBill (data) {
    return co(reissueBillGen(data))
  }
}

export default PrintService
